<template>
    <div class="login-wrap">
        <div class="ms-login">
            <el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
                <div class="title">hello !</div>
                <div class="title-tips">欢迎来到系统！</div>
                <el-form-item prop="account" class="m-top">
                    <el-input v-model="param.account" placeholder="account">
                        <el-button slot="prepend" icon="el-icon-lx-people"></el-button>
                    </el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input
                        type="password"
                        placeholder="password"
                        v-model="param.password"
                        @keyup.enter.native="submitForm()"
                    >
                        <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                    </el-input>
                </el-form-item>
                <div class="login-btn">
                    <el-button type="primary" @click="submitForm()">登录</el-button>
                </div>
            </el-form>
        </div>
    </div>
</template>

<script>
import login from '../api/login';
export default {
    data: function() {
        return {
            param: {
                account: 'admin',
                password: '123456',
            },
            rules: {
                account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
            },
        };
    },
    methods: {
        submitForm() {
            var _that =this;
            this.$refs.login.validate(valid => {
                if (valid) {
                    login.loginIn(_that.param).then(response => {
                        const data = response.data
                        this.$message.success('登录成功');
                        localStorage.setItem("X-Token", data.token);
                        localStorage.setItem('ms_username',  data.user.account);
                        localStorage.setItem('ms_userid',  data.user.id);
                        this.$router.push('/');
                    }).catch(error => {
                        this.$message.success('登录失败');
                    })
                } else {
                    this.$message.error('请输入账号和密码');
                    console.log('登录失败');
                    return false;
                }
            });
        },
    },
};
</script>

<style scoped>
.login-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background-image: url(../assets/img/background.jpg);
    background-size: 100%;
}
.title {
      font-size: 54px;
      font-weight: 500;
      color: rgba(14, 18, 26, 1);
}

.title-tips {
    margin-top: 29px;
    font-size: 26px;
    font-weight: 400;
    color: rgba(14, 18, 26, 1);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 20px;
    color: #fff;
    border-bottom: 1px solid #ddd;
}
.ms-login {
    position: absolute;
    left: 50%;
    width: 350px;
    margin: calc((100vh - 425px) / 2) 10% 10%;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.3);
    overflow: hidden;
}
.ms-content {
   
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}

.m-top{
    margin-top: 10px;
}
</style>
